<?php

/*
 * @Date: 2025-08-09 01:32:49
 * @LastEditors: 贾二小 erxiao.jia@outlook.com
 * @LastEditTime: 2025-10-15 23:12:34
 * @FilePath: /admin-api/routes/api.php
 */

use App\Http\Controllers\AuthController;
use App\Http\Controllers\MenuController;
use App\Http\Controllers\PermissionController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\UploadController;
use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Route;

Route::controller(AuthController::class)->prefix('auth')->group(function () {
    Route::post('login', 'login');
    Route::post('register', 'register');
    Route::get('user', 'user')->middleware('auth:sanctum');
    Route::post('logout', 'logout')->middleware('auth:sanctum');
    Route::put('password', 'password')->middleware('auth:sanctum');
});





Route::group(['middleware' => 'auth:sanctum'], function () {

    Route::get('user/{user}/roles', [UserController::class, 'roles']);
    Route::post('user/{user}/roles', [UserController::class, 'syncRoles']);
    Route::apiResource('user', UserController::class);

    Route::get('permission/all', [PermissionController::class, 'permission']);
    Route::apiResource('permission', PermissionController::class);

    Route::get('role/all', [RoleController::class, 'role']);
    Route::get('role/{role}/permissions', [RoleController::class, 'permissions']);
    Route::post('role/{role}/permissions', [RoleController::class, 'syncPermissions']);
    Route::apiResource('role', RoleController::class);

    //文件上传
    Route::controller(UploadController::class)->prefix('upload')->group(function () {
        Route::post('avatar', 'avatar');
    });



    Route::apiResource('menu', MenuController::class);

});
